package com.jsb.laundry.controller;

import com.jsb.laundry.common.constant.JSBSpecialID;
import com.jsb.laundry.common.constant.LaundryModuleConstants;
import com.jsb.laundry.common.response.WebResponse;
import com.jsb.laundry.dao.LaundryIndexDao;
import com.jsb.laundry.dao.StoreSettlementDao;
import com.jsb.laundry.model.dto.ActivityModuleDto;
import com.jsb.laundry.model.dto.CategoryDto;
import com.jsb.laundry.model.entity.Banner;
import com.jsb.laundry.model.entity.StoreSettlement;
import com.jsb.laundry.model.v1.LaundryActivityVo;
import com.jsb.laundry.model.v1.LaundryCategory;
import com.jsb.laundry.model.vo.IndexVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Api(tags = {"首页"})
@RestController
@RequestMapping("/laundryV2")
public class LaundryIndexController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LaundryIndexController.class);

    @Resource
    private LaundryIndexDao laundryIndexDao;
    @Resource
    private StoreSettlementDao storeSettlementDao;

    /**
     * 获取首页数据
     */
    @ApiOperation(value = "首页数据", notes = "首页数据", httpMethod = "POST")
    @PostMapping("/getIndexData")
    public WebResponse<IndexVo> getIndexData() {
        IndexVo res = new IndexVo();
        List<Banner> var0 = laundryIndexDao.getBanner();
        List<CategoryDto> var1 = laundryIndexDao.findCateAndMinPrice();

        List<String> activityIdList = new ArrayList() {
            {
                add(JSBSpecialID.JSB_01);
                add(JSBSpecialID.JSB_MONTH_1_298);
                add(JSBSpecialID.JSB_MONTH_2_398);
            }
        };
        List<ActivityModuleDto> var2 = laundryIndexDao.getLaundryActivity(LaundryModuleConstants.LAUNDRY_ACTIVITY_ID, activityIdList);
        res.setBannerModule(var0).setCategoryModule(var1).setActivityModule(var2);

        return WebResponse.successData(res);
    }

    @ApiOperation(value = "商铺入驻", notes = "商铺入驻", httpMethod = "POST")
    @PostMapping("storeSettlement")
    @Transactional
    public WebResponse storeSettlement(@RequestBody StoreSettlement storeSettlement) {
        int insert = storeSettlementDao.insert(storeSettlement);
        return WebResponse.successData(insert);
    }

}
